package com.qianfeng.biquge.controller;


import com.qianfeng.biquge.pojo.Categories;
import com.qianfeng.biquge.service.CategorieService;
import com.qianfeng.biquge.vo.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.io.UnsupportedEncodingException;
import java.util.List;

@RestController
@RequestMapping("/category")
public class CategoriesController {

    @Autowired
    private CategorieService categorieService;

    @PostMapping("/newcategory/{categoryName}")
    public R addCategorie(@PathVariable String categoryName) throws UnsupportedEncodingException {

        Categories categorie = categorieService.addCategorie(categoryName);

        return R.setOk(categorie);

    }

    @GetMapping("/categories")
    public R getAllOKCategorie(){

        List<Categories> categoriesList = categorieService.getAllOKCategorie();

        return R.setOk(categoriesList);

    }

    @GetMapping("/categoriesall")
    public R getAllCategorieIsDelete(){

        List<Categories> categoriesList = categorieService.getAllCategorieIsDelete();

        return R.setOk(categoriesList);

    }

    @PutMapping("/update")
    public R updateCategorie(@RequestBody Categories categories){

        int i = categorieService.updateCategorie(categories);

        return R.setOk(categories);

    }

    @DeleteMapping("/delete/{categoryId}")
    public R deleteCategorie(@PathVariable Long categoryId){

        int i = categorieService.deleteCategorie(categoryId);

        return R.setOk(i);

    }


}
